package com.sys.servlet.mgr.course;


import com.sys.entity.Course;
import com.sys.entity.Customer;
import com.sys.entity.Trainer;
import com.sys.pojo.JsonResult;
import com.sys.service.CourseService;
import com.sys.service.CustomerService;
import com.sys.utils.WriteJson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/mgr/course/showById")
public class ShowByIdServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        JsonResult jr = new JsonResult();

        String cid = req.getParameter("cid");
        if (cid == null || "".equals(cid)){
            jr.setCode(600);
            jr.setMsg("请传入cid");
            WriteJson.write(resp,jr);
            return;
        }
        CourseService courseService = new CourseService();
        try {
            Course course = courseService.showById(cid);
            jr.setCode(0);
            jr.setData(course);
        } catch (Exception e) {
            e.printStackTrace();
            jr.setCode(500);
            jr.setMsg("操作发生错误");
        }
        WriteJson.write(resp, jr);
    }
}
